<template>
	<view>
		<view class="mainpadding2 ffffff">
			<u-tabs :list="tabs" lineColor="#1BA95B" :scrollable="false" @click="changetab" :activeStyle="{
				    color: '#1BA95B',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}" :inactiveStyle="{
				            color: '#333333',
							fontWeight: '400',
				            transform: 'scale(1)'
				        }" itemStyle="padding-left: 5px; padding-right: 10px; height: 44px;"></u-tabs>
		</view>
		<!-- 内容 -->
		<view class="mainpadding2">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
			</view>
			<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id" @click="jumpurl('/pages_mypage/saishiddxq?id=',item.id)">
				<view class="flexbetween xiahuaxian">
					<view class="titletext sanshier xiaohei fonweight">{{item.createtime_text}}</view>
					<view class="xiaolv strongtext" v-if="item.hx_status==1">未核销</view>
					<view class="xiaolv strongtext" v-if="item.hx_status==2">已核销</view>
					<view class="xiaohui strongtext" v-if="item.hx_status==3">已取消</view>
					<view class="xiaohuang strongtext" v-if="item.hx_status==4">取消审核中</view>
				</view>
				<view class="xiahuaxian margin_top">
					<view class="flexbetween">
						<view class="shilitu margin_right2">
							<image :src="item.ss.image_text" mode=""></image>
						</view>
						<view class="flexcolumn" style="width: 69%;align-items: flex-start;height: 160rpx;justify-content: space-between;">
							<view class="titletext xiaohei fonweight yhxk">{{item.ss.name}}</view>
							<view class="strongtext xiaohui nofonweight">
								开始时间：{{item.ss.bs_starttime_text}}</view>
							<view class="strongtext xiaohui nofonweight">
								截至时间：{{item.ss.bs_endtime_text}}</view>
							<view class="sanshier xiaohong fonweight">￥{{item.ss.price}}</view>
						</view>
					</view>
				</view>
				<view class="flexright margin_top">
					<view class="baibtn" v-if="item.hx_status==1 && item.is_cancel" @click.stop="cancelitem(item.id)">取消订单</view>
					<view class="baibtn" v-if="item.hx_status==3 || item.hx_status==2" @click.stop="delitem(item.id)">删除订单</view>
					<view class="lvbtn margin_left">查看详情</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// 0=全部,1=待支付,2=待发货,3=待收货,4=已完成,5=已取消
				tabs: [{
						name: '全部',
						value: 0,
					},
					{
						name: '未核销',
						value: 1
					},
					{
						name: '已核销',
						value: 2
					},
					{
						name: '已取消',
						value: 3
					}
				],
				tabsid: 0,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					hx_status:this.tabsid
				}
				let url = '/api/user/ssBmIndex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			delitem(id) {
				httpRequest.modal('提示', '确认删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/user/ssBmDelete', 'GET', {
							id
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								this.init()
							}
						})
					}
				})
			},
			cancelitem(id) {
				httpRequest.modal('提示', '确认取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/user/ssBmCancel', 'GET', {
							id
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								this.init()
							}
						})
					}
				})
			},
			jumpurl(url,id){
				uni.navigateTo({
					url:url+id
				})
			},
			changetab(e) {
				this.tabsid = e.value
				this.init()
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F9F9F9;
	}
	.shilitu {
		width: 200rpx;
		height: 160rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}
</style>